import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../common/style/colors.dart';

class ColorStyle {
  final Color color;
  final Color bgColor;
  final Gradient? gradient;

  ColorStyle({
    required this.color,
    required this.bgColor,
    this.gradient,
  });
}

class AppButton extends StatelessWidget {
  final VoidCallback? onPressed;
  final String text;
  final double? fontSize;
  final ColorStyle? colorStyle;
  final ColorStyle? disabledColorStyle;
  final bool enabled;

  const AppButton({
    Key? key,
    this.enabled = true,
    this.onPressed,
    required this.text,
    this.fontSize,
    this.colorStyle,
    this.disabledColorStyle,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // bool hasGradient = colorStyle!=null&&
    var textView = Text(
      text,
      style: TextStyle(
          color: onPressed == null
              ? disabledColorStyle == null
              ? AppColors.color66
              : disabledColorStyle!.bgColor
              : colorStyle == null
              ? AppColors.white
              : colorStyle!.bgColor,
          fontSize: fontSize ?? 15.sp),
    );
    var btn = ElevatedButton(
      style: ButtonStyle(
          backgroundColor: onPressed == null
              ? MaterialStateProperty.all(
              disabledColorStyle == null ? AppColors.btnNormalBg : disabledColorStyle!.bgColor)
              : MaterialStateProperty.all(colorStyle == null ? AppColors.btnNormalBg : colorStyle!.bgColor)),
      onPressed: onPressed,
      child: Center(
        child:textView,
      ),
    );
    var _gradient = onPressed == null ? disabledColorStyle?.gradient : colorStyle?.gradient;
    var view = Container(
      child: btn,
      decoration: BoxDecoration(gradient: _gradient),
    );
    return view;
  }
}
